<div class="content-auto">
<div class="breadcrumb">
    <span>(<strong><?php echo $title;?></strong>)</span>
</div>
<?php echo form_open('itstock/stockedit',array('class'=>'form-horizontal form-validate','id'=>'frm'));?>
<fieldset>
    <table class="table-form-submit">
        <tr>
            <td><label for="ittype_id">Category</label></td>
            <td>
                <?php echo form_dropdown('ittype_id', $itTypeList,$stock['ittype_id'], 'class="form-control"') ?>
            </td>
        </tr>
        <tr>
            <td><label for="model_id">Model</label></td>
            <td>
                <?php echo form_dropdown('model_id', $modelList,$stock['model_id'], 'class="form-control"') ?>
            </td>
        </tr>
        <tr>
            <td><label for="item">Item *</label></td>
            <td><input type="text" name="item" value="<?php echo $stock['item']; ?>" placeholder="item name" class="form-control" required /></td>
        </tr>
         <tr>
            <td><label for="unit">Unit *</label></td>
            <td>
             <?php
                $inunit = id_clean($stock['unit']) - (id_clean($stock['unitused']) + id_clean($stock['unitbroken']));  
            ?>
                <span>(Bought: <?php echo $stock['unit'].', ';?></span>
                <span>In stock: <?php echo $inunit;?>)</span>
                <input type="text" name="unit" value="<?php echo $stock['unit']; ?>" placeholder="number of items" class="form-control control-width" required />
            </td>
        </tr>
        <tr>
            <td><label for="cpu">Cost Per Unit *</td>
            <td><input type="text" name="cpu" value="<?php echo $stock['cpu']; ?>" placeholder="cost per unit" class="form-control control-width" required /></td>
        </tr>
        <tr>
            <td><label for="datepurchased">Purchased Date *</td>
            <td><input type="text" name="datepurchased" value="<?php echo $stock['datepurchased']; ?>" placeholder="purchased date" data-date-format="yyyy/mm/dd" class="form-control datepicker" required /></td>
        </tr>
    <?php if($inunit > 0){ ?>
        <tr>
            <td><label for="status_id">Status</label></td>
            <td>
                <?php echo form_dropdown('status_id', $statusList,array(), 'class="form-control status-select"') ?>
            </td>
        </tr>
    <?php }else{ $data = array(1=>'In Stock'); ?>
        <tr>
            <td><label for="status_id">Status</label></td>
            <td>
                <?php echo form_dropdown('status_id', $data,array(), 'class="form-control status-select"') ?>
            </td>
        </tr>
    <?php }?>
        <tr class="hidden-branch-tr">
            <td><label class="branch-hidden"  for="note">Note</td>
            <td><textarea name="note" class="form-control branch-hidden note"></textarea></td>
        </tr>
        <tr class="hidden-broken-tr">
            <td><label class="broken-hidden"  for="notebroken">Note</td>
            <td><textarea name="notebroken" class="form-control broken-hidden note"></textarea></td>
        </tr>
        <tr class="hidden-branch-tr">
            <td><label  class="branch-hidden" for="dateused">Date </td>
            <td><input type="text" name="dateused" placeholder="used or transfered date" data-date-format="yyyy/mm/dd" class="form-control branch-hidden datepicker" /></td>
        </tr>
        <tr class="hidden-branch-tr">
            <td><label class="branch-hidden" for="unitused">Unit *</label></td>
            <td><input type="text" name="unitused" placeholder="number of items" class="form-control control-width branch-hidden" required /></td>
        </tr>
        <tr class="hidden-branch-tr">
            <td><label  class="branch-hidden"  for="label">Label</label></td>
            <td><input type="text" name="label" placeholder="Label item" class="form-control control-width branch-hidden" /></td>
        </tr>
    <?php if(isset($_SESSION['branch']) && $_SESSION['branch'] == '00HO00') { ?>
        <tr class="hidden-branch-tr">
            <td><label  class="branch-hidden" for="branch_id">Branch *</label></td>
            <td>
                <?php echo form_dropdown('branch_id', $branchList,array(), 'class="form-control branch-hidden" required') ?>
            </td>
        </tr>
         <tr class="hidden-branch-tr">
            <td><label  class="branch-hidden" for="location_id">Location</label></td>
            <td>
                <?php echo form_dropdown('location_id', $locationList,array(), 'class="form-control branch-hidden"') ?>
            </td>
        </tr>
    <?php } else {
        echo form_hidden('branch_id', $_SESSION['branch']);
    }?>
        <tr class="hidden-branch-tr">
            <td><label class="branch-hidden" for="staff">Staff</label></td>
            <td><input type="text" name="staff" placeholder="Staff name" class="form-control control-width branch-hidden" /></td>
        </tr>
        <tr class="hidden-broken-tr type-tr">
            <td><label class="broken-hidden" for="unitbroken">Unit</label></td>
            <td><input type="text" name="unitbroken" placeholder="Number of items" class="form-control control-width broken-hidden" /></td>     
        </tr>
        <tr class="hidden-broken-tr type-tr">
            <td><label  class="broken-hidden"  for="labelbroken">Label</label></td>
            <td><input type="text" name="labelbroken" placeholder="Label item" class="form-control control-width broken-hidden" /></td>
        </tr>
        <tr>
            <td><label for="remark">Remark</td>
            <td><textarea name="remark" class="form-control"><?php echo $stock['remark']; ?></textarea></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <label class="checkbox">
                <?php if($stock['activate'] == 1){ ?>
                    <input name="activate" type="checkbox" checked="checked" /> Active
                <?php }else { ?>
                    <input name="activate" type="checkbox" /> Active
                <?php } ?>
                </label>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <?php 
                    echo form_hidden('stock_id',$stock['stock_id']);
                    echo form_hidden('item_id',$stock['itused_id']);
                ?>
                <?php echo $form; ?>
            </td>
        </tr>
    </table>
 </fieldset> 
<?php echo form_close();?>
</div>